Component({
  properties: {
    // 这里可以定义组件的属性，例如 panelHeight, handleHeight, threshold 等
  },
  data: {
    isDragging: false,
    panelHeight: 300, // 面板总高度
    handleHeight: 50, // 把手高度
    threshold: 100, // 展开/收起的阈值
    position: 300, // 面板当前位置
    startY: 0,
    startPosition: 800,
    currentY: 0,
    currentX:0,
    ismove: false
  },
  methods: {
    onTouchStart(e) {
 
      this.setData({
        isDragging: true,
        startY: e.touches[0].clientY,
        startPosition: this.data.position,
        ismove: false
      });
    },
    onTouchMove(e) {
      this.setData({
        ismove: true
      })
 
     
      
      if (!this.data.isDragging) return;

      this.setData({
        currentY: e.touches[0].clientY,
        currentX:e.touches[0].clientX
      })

    },
    onTouchEnd(e) {
      if (!this.data.ismove) return
      this.setData({
        isDragging: false,
        ismove: true
      })
      const diff = this.data.currentY - this.data.startY;
      const dampenedDiff = diff * 0.5;
      let newPosition = this.data.startPosition + dampenedDiff;
      // //如果在水平线上要下降或在下位线要下降      
      console.log(this.data.position,newPosition);
      if (this.data.position == 300 && newPosition > 300) {
        this.triggerEvent('customEvent', 600);
        return this.setData({
          position: 600
        })

      }
      //在下位线要上升
      if (newPosition < 600 && this.data.position == 600 && newPosition > 300) {
        this.triggerEvent('customEvent', 300);

        return this.setData({
          position: 300
        })
      }

      //在水平线上要上升或在上位线上要上升
      if (newPosition < 300 && this.data.position == 300 && newPosition > 0) {
        this.triggerEvent('customEvent', 0);

        return this.setData({
          position: 0
        })
      }

      //在上位线要下降
      if (newPosition < 300 && this.data.position == 0 && newPosition > 0) {
        this.triggerEvent('customEvent', 300);

        return this.setData({
          position: 300
        })
      }


    }
  }
});